package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;

import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionDao permissionDao;
    @Override
    public void del(Integer[] ids) {
        for (Integer id : ids) {
            permissionDao.delRoleAndPermission(id);
            permissionDao.del(id);
        }
    }

    @Override
    public void update(Permission permission) {
        permissionDao.update(permission);
    }

    @Override
    public Permission find(Integer id) {
        return permissionDao.find(id);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Permission> permissions=permissionDao.findPage(queryPageBean.getQueryString());
        return new PageResult(permissions.getTotal(),permissions );
    }

    @Override
    public List<Permission> findAll() {
        return permissionDao.findPage(null);
    }

    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }
}
